#include <sys_config.h>

#ifdef HILINK_SUPPORT
#include <types.h>
#include <osal/osal.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>
#include <api/libosd/osd_lib.h>
#include <api/libpub/lib_frontend.h>

#include "osdobjs_def.h"
#include "osd_config.h"
#include "string.id"
#include "images.id"
#include "menus_root.h"
#include "win_com.h"
#include "win_com_popup.h"

#include <hld/ali_3g_mdm/ali_3g_mdm_api.h>
#include <api/libhilink/lib_hilink.h>
#include "copper_common/com_api.h"

#include "mobile_input.h"

#ifdef	_BUILD_OTA_E_
#define WIN_SH_IDX	  	WSTL_WINSEARCH_03_HD
#else
#define WIN_SH_IDX	  	WSTL_WIN_BODYRIGHT_01_HD
#endif

#define CON_SH_IDX   WSTL_BUTTON_01_HD
#define CON_HL_IDX   WSTL_BUTTON_05_HD
#define CON_SL_IDX   WSTL_BUTTON_01_HD
#define CON_GRY_IDX  WSTL_BUTTON_07_HD

#define TXT_SH_IDX   WSTL_BUTTON_01_FG_HD
#define TXT_HL_IDX   WSTL_BUTTON_02_FG_HD
#define TXT_SL_IDX   WSTL_BUTTON_01_FG_HD
#define TXT_GRY_IDX  WSTL_BUTTON_07_HD

#define SEL_SH_IDX   WSTL_BUTTON_01_FG_HD
#define SEL_HL_IDX   WSTL_BUTTON_04_HD
#define SEL_SL_IDX   WSTL_BUTTON_01_FG_HD
#define SEL_GRY_IDX  WSTL_BUTTON_07_HD

#define EDF_SH_IDX   WSTL_BUTTON_01_FG_HD
#define EDF_HL_IDX   WSTL_BUTTON_04_HD
#define EDF_SL_IDX   WSTL_BUTTON_01_FG_HD
#define EDF_GRY_IDX  WSTL_BUTTON_07_HD

#ifndef SD_UI
#ifdef	_BUILD_OTA_E_
#define	W_W         692             //493
#define	W_H         488             //320
#define	W_L         GET_MID_L(W_W)  //60
#define	W_T         98              //GET_MID_T(W_H)//60
#define CON_L		(W_L + 24)
#define CON_T		(W_T + 4)
#define CON_W		(W_W - 48)
#else

#ifndef SUPPORT_CAS_A
/* define in win_com_menu_define.h already */
#define	W_L     	248
#define	W_T     	98
#define	W_W     	692
#define	W_H     	488
#endif

#define CON_L		(W_L+20)
#define CON_T		(W_T + 4)
#define CON_W		(W_W - 60)
#endif

//#define CON_L		W_L
#define CON_H		40
#define CON_GAP		8

#define TXT_L_OF  	10
#define TXT_W  		260
#define TXT_H		CON_H
#define TXT_T_OF	((CON_H - TXT_H)/2)

#define SEL_L_OF  	(TXT_L_OF + TXT_W)
#define SEL_W  		(CON_W-TXT_W-20)
#define SEL_H		CON_H
#define SEL_T_OF	((CON_H - SEL_H)/2)

#define LINE_L_OF	0
#define LINE_T_OF  	(CON_H+2)
#define LINE_W		CON_W
#define LINE_H     	2

#define ITEM_H          CON_H
#define LIST_ITEMCNT    3
#define ITEM_GAP	6//8

#define LST_L		(CON_L + 10)
#define LST_T		CON_T
#define LST_W		(W_W - 40)
#define LST_GAP 	4
#define LST_H		((ITEM_H+ITEM_GAP)*LIST_ITEMCNT+LST_GAP)

#define HILINK_LINE_L	(LST_L)
#define HILINK_LINE_T  	(LST_T + LST_H + 14)
#define HILINK_LINE_W	(LST_W-40)
#define HILINK_LINE_H   2

#define COLBTN_L (HILINK_LINE_L)
#define COLBTN_T (HILINK_LINE_T + LST_GAP)

#define CAPSFLG_L (COLBTN_L + 100 + 20)
#define CAPSFLG_T (COLBTN_T)

#else
#ifdef	_BUILD_OTA_E_
#define	W_W         482             //493
#define	W_H         360             //320
#define	W_L         GET_MID_L(W_W)  //60
#define	W_T         60              //GET_MID_T(W_H)//60
#define CON_L		(W_L + 24)
#define CON_T		(W_T + 4)
#define CON_W		(W_W - 40)
#else
#define	W_L     	105//384
#define	W_T     	57//138
#define	W_W     	482
#define	W_H     	370
#define CON_L		(W_L+20)
#define CON_T		(W_T + 8)
#define CON_W		(W_W - 40)
#endif

#define CON_H		30
#define CON_GAP		8

#define TXT_L_OF  	10
#define TXT_W  		180
#define TXT_H		CON_H
#define TXT_T_OF	((CON_H - TXT_H)/2)

#define SEL_L_OF  	(TXT_L_OF + TXT_W)
#define SEL_W  		(CON_W-TXT_W-20)
#define SEL_H		CON_H
#define SEL_T_OF	((CON_H - SEL_H)/2)

#define LINE_L_OF	0
#define LINE_T_OF  	(CON_H+2)
#define LINE_W		CON_W
#define LINE_H     	2

#define ITEM_H          CON_H
#define LIST_ITEMCNT    4
#define ITEM_GAP	6//8

#define LST_L		(CON_L + 10)
#define LST_T		CON_T
#define LST_W		(W_W - 40)
#define LST_GAP 	4
#define LST_H		((ITEM_H+ITEM_GAP)*LIST_ITEMCNT+LST_GAP)

#define HILINK_LINE_L	(LST_L)
#define HILINK_LINE_T  	(LST_T + LST_H + 14)
#define HILINK_LINE_W	(LST_W-40)
#define HILINK_LINE_H   2

#define COLBTN_L (HILINK_LINE_L)
#define COLBTN_T (HILINK_LINE_T + LST_GAP)

#define CAPSFLG_L (COLBTN_L + 100 + 40)
#define CAPSFLG_T (COLBTN_T)

#endif

extern CONTAINER g_win_hilink_profile;

extern CONTAINER g_win_hilink_apn_con;
extern CONTAINER g_win_hilink_user_con;
extern CONTAINER g_win_hilink_password_con;

extern TEXT_FIELD hilink_apn;
extern TEXT_FIELD hilink_user;
extern TEXT_FIELD hilink_password;

extern EDIT_FIELD edit_hilink_apn;
extern EDIT_FIELD edit_hilink_user;
extern EDIT_FIELD edit_hilink_password;

extern TEXT_FIELD w_hilink_profile_line0;
extern TEXT_FIELD w_hilink_profile_line1;
extern TEXT_FIELD w_hilink_profile_line2;

extern TEXT_FIELD hilink_profile_line;

extern TEXT_FIELD hilink_profile_btntxt_ok;
extern TEXT_FIELD hilink_profile_btntxt_cancel;
extern TEXT_FIELD hilink_profile_btntxt_caps;
extern TEXT_FIELD hilink_profile_btntxt_del;

extern BITMAP   hilink_profile_btnbmp_ok;
extern BITMAP   hilink_profile_btnbmp_cancel;
extern BITMAP   hilink_profile_btnbmp_caps;
extern BITMAP   hilink_profile_btnbmp_del;


static VACTION win_hilink_profile_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT win_hilink_profile_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static PRESULT win_hilink_profile_item_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);
static VACTION win_hilink_profile_item_con_keymap(POBJECT_HEAD pObj, UINT32 key);

static VACTION win_hilink_profile_edf_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT win_hilink_profile_edf_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);


#define LDEF_CON(root, varCon,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,hl,conobj,focusID)		\
    DEF_CONTAINER(varCon,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, CON_SH_IDX,hl,CON_SL_IDX,CON_GRY_IDX,   \
    win_hilink_profile_item_con_keymap,win_hilink_profile_item_con_callback,  \
    conobj, ID,1)


#define LDEF_EDIT(root, varNum, nxtObj, ID, l, t, w, h,style,max_len,cursormode,pat,pre,sub,str)	\
    DEF_EDITFIELD(varNum,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,ID,ID,ID,ID, l,t,w,h, EDF_SH_IDX,EDF_HL_IDX,EDF_SL_IDX,EDF_GRY_IDX,   \
    win_hilink_profile_edf_keymap,win_hilink_profile_edf_callback,  \
    C_ALIGN_CENTER | C_ALIGN_VCENTER, 30,0,style,pat,max_len,cursormode,pre,sub,str)

#define LDEF_TXT(root,varTxt,nxtObj,l,t,w,h,resID)		\
    DEF_TEXTFIELD(varTxt,root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, TXT_SH_IDX,TXT_HL_IDX,TXT_SL_IDX,TXT_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_LEFT | C_ALIGN_VCENTER, 0,0,resID,NULL)
/*
#define LDEF_TXT_BTN(root,varTxt,nextObj,varLine,ID,IDu,IDd,l,t,w,h,resID)		\
    DEF_TEXTFIELD(varTxt,&root,nextObj,C_ATTR_ACTIVE,0, \
    ID,ID,ID,IDu,IDd, l,t,w,h, CON_SH_IDX,CON_HL_IDX,CON_SL_IDX,CON_GRY_IDX,   \
    otaset_btn_keymap,otaset_btn_callback,  \
    C_ALIGN_LEFT | C_ALIGN_VCENTER, TXT_L_OF,0,resID,NULL)\
	LDEF_LINE(&root,varLine,NULL,1,1,1,1,1,l + LINE_L_OF, t + LINE_T_OF + 10,LINE_W,LINE_H,0,0)
*/

#define LDEF_MENU_ITEM_EDF(root,varCon,nxtObj,varTxt,varNum,varLine,ID,IDu,IDd,\
						l,t,w,h,resID,style,max_len,cursormode,pat,pre,sub,str) \
    LDEF_CON(&root,varCon,nxtObj,ID,ID,ID,IDu,IDd,CON_L,t,CON_W,CON_H,CON_HL_IDX,&varTxt,ID)   \
    LDEF_TXT(&varCon,varTxt,&varNum,l + TXT_L_OF,t + TXT_T_OF,TXT_W,TXT_H,resID)    \
    LDEF_EDIT(&varCon,varNum,NULL/*&varLine*/,ID,l + SEL_L_OF ,t + SEL_T_OF,SEL_W,SEL_H,style,max_len,cursormode,pat,pre,sub,str)\
	LDEF_LINE(&varCon,varLine,NULL,1,1,1,1,1,l + LINE_L_OF, t + LINE_T_OF,LINE_W,LINE_H,0,0)

#define LDEF_HILINK_LINE(root, varTxt, nxtObj, l, t, w, h, str)		\
    DEF_TEXTFIELD(varTxt,&root,nxtObj,C_ATTR_ACTIVE,0, \
                  0, 0, 0, 0, 0, l, t, w, h, WSTL_LINE_MENU_HD,WSTL_LINE_MENU_HD,WSTL_LINE_MENU_HD,WSTL_LINE_MENU_HD,   \
                  NULL,NULL,  \
                  C_ALIGN_CENTER | C_ALIGN_VCENTER, 0,0,0,str)

#ifndef SD_UI
#define LDEF_BMP_BTN(root,varBmp,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,iconID) \
	DEF_BITMAP(varBmp, root, nxtObj, C_ATTR_ACTIVE,0, 	\
	ID,IDl,IDr,IDu,IDd, l, t, 28, 40, WSTL_TEXT_04_8BIT, WSTL_TEXT_04_8BIT, WSTL_TEXT_04_8BIT, WSTL_TEXT_04_8BIT,	\
	NULL, NULL,	\
	 C_ALIGN_LEFT | C_ALIGN_VCENTER, 0, 0, iconID)
#else
#define LDEF_BMP_BTN(root,varBmp,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,iconID) \
	DEF_BITMAP(varBmp, root, nxtObj, C_ATTR_ACTIVE,0, 	\
	ID,IDl,IDr,IDu,IDd, l, t, 28, 24, WSTL_TEXT_04_8BIT, WSTL_TEXT_04_8BIT, WSTL_TEXT_04_8BIT, WSTL_TEXT_04_8BIT,	\
	NULL, NULL,	\
	 C_ALIGN_LEFT | C_ALIGN_VCENTER, 0, 0, iconID)
#endif
#define LDEF_TXT_BTN_EXT(root,varTxt,nxtObj,l,t,w,h,ID)	\
	DEF_TEXTFIELD(varTxt,root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, TXT_SH_IDX,TXT_HL_IDX,TXT_SL_IDX,TXT_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_LEFT | C_ALIGN_VCENTER, 0,0,ID,NULL)

#define LDEF_WIN(varCon,nxtObj,l,t,w,h,focusID)		\
    DEF_CONTAINER(varCon,NULL,NULL,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, WIN_SH_IDX,WIN_SH_IDX,WIN_SH_IDX,WIN_SH_IDX,   \
    win_hilink_profile_keymap,win_hilink_profile_callback,  \
    nxtObj, focusID,0)

static UINT16 hilink_profile_apn_strs[30] = {0};
static UINT16 hilink_profile_user_strs[30] = {0};
static UINT16 hilink_profile_password_strs[30] = {0};

static char string_pattern[] = "s15";
static char pwd_pattern[] = "m-*15";
//static char num_pattern[] = "r20~9999";

//const UINT8 hilink_apn_max_len = 15;
//const UINT8 hilink_user_max_len = 15;
//const UINT8 hilink_password_max_len = 15;


LDEF_MENU_ITEM_EDF(g_win_hilink_profile,g_win_hilink_apn_con,&g_win_hilink_user_con,hilink_apn,edit_hilink_apn,w_hilink_profile_line0,1,3,2,\
			CON_L, CON_T + (CON_H + CON_GAP)*0, CON_W, CON_H, RS_HILINK_APN, \
			NORMAL_EDIT_MODE, /*hilink_apn_max_len*/ 17 ,CURSOR_NORMAL, string_pattern, NULL,NULL,hilink_profile_apn_strs)

LDEF_MENU_ITEM_EDF(g_win_hilink_profile,g_win_hilink_user_con,&g_win_hilink_password_con,hilink_user,edit_hilink_user,w_hilink_profile_line1,2,1,3,\
			CON_L, CON_T + (CON_H + CON_GAP)*1, CON_W, CON_H, RS_HILINK_USER, \
			NORMAL_EDIT_MODE, /*hilink_user_max_len*/ 17,CURSOR_NORMAL, string_pattern, NULL,NULL,hilink_profile_user_strs)

LDEF_MENU_ITEM_EDF(g_win_hilink_profile,g_win_hilink_password_con,&hilink_profile_line,hilink_password,edit_hilink_password,w_hilink_profile_line2,3,2,1,\
			CON_L, CON_T + (CON_H + CON_GAP)*2, CON_W, CON_H, RS_HILINK_PASSWORD, \
			NORMAL_EDIT_MODE, /*hilink_password_max_len*/ 17 ,CURSOR_NORMAL, pwd_pattern, NULL, NULL,hilink_profile_password_strs)


LDEF_HILINK_LINE(g_win_hilink, hilink_profile_line, &hilink_profile_btnbmp_caps, HILINK_LINE_L, HILINK_LINE_T, HILINK_LINE_W, HILINK_LINE_H, NULL)

LDEF_BMP_BTN(&g_win_hilink_profile, hilink_profile_btnbmp_caps,&hilink_profile_btntxt_caps,0,0,0,0,0, \
		COLBTN_L, COLBTN_T,IM_EPG_COLORBUTTON_RED)
LDEF_TXT_BTN_EXT(&g_win_hilink_profile, hilink_profile_btntxt_caps, &hilink_profile_btnbmp_del, \
		COLBTN_L+28*1, COLBTN_T, 100, 40, RS_COM_CAPS)
LDEF_BMP_BTN(&g_win_hilink_profile, hilink_profile_btnbmp_del,&hilink_profile_btntxt_del,0,0,0,0,0, \
		COLBTN_L+230+28*1, COLBTN_T,IM_EPG_COLORBUTTON_GREEN)
LDEF_TXT_BTN_EXT(&g_win_hilink_profile, hilink_profile_btntxt_del, &hilink_profile_btnbmp_ok, \
		COLBTN_L+230+28*2, COLBTN_T, 70, 40, RS_DEL)		
LDEF_BMP_BTN(&g_win_hilink_profile, hilink_profile_btnbmp_ok,&hilink_profile_btntxt_ok,0,0,0,0,0, \
		COLBTN_L+300+28*2, COLBTN_T,IM_EPG_COLORBUTTON_YELLOW)
LDEF_TXT_BTN_EXT(&g_win_hilink_profile, hilink_profile_btntxt_ok, &hilink_profile_btnbmp_cancel, \
		COLBTN_L+300+28*3, COLBTN_T, 100, 40, RS_NET_APPLY)
LDEF_BMP_BTN(&g_win_hilink_profile, hilink_profile_btnbmp_cancel,&hilink_profile_btntxt_cancel,0,0,0,0,0, \
		COLBTN_L+400+28*3, COLBTN_T,IM_EPG_COLORBUTTON_BLUE)
LDEF_TXT_BTN_EXT(&g_win_hilink_profile, hilink_profile_btntxt_cancel, NULL, \
		COLBTN_L+400+28*4, COLBTN_T, 124, 40, RS_COMMON_CANCEL)

LDEF_WIN(g_win_hilink_profile,&g_win_hilink_apn_con,W_L, W_T,W_W,W_H,1)

//#define VACT_CHANGE_SUB	(VACT_PASS + 1)
#define VACT_OK				(VACT_PASS + 1)
#define VACT_CANCEL		(VACT_PASS + 2)

static VACTION win_hilink_profile_keymap(POBJECT_HEAD pObj, UINT32 key)
{
    VACTION act = VACT_PASS;
    
    switch(key)
    {
    case V_KEY_UP:
        act = VACT_CURSOR_UP;
        break;
    case V_KEY_DOWN:
        act = VACT_CURSOR_DOWN;
        break;      
    case V_KEY_EXIT:
    case V_KEY_MENU:
        act = VACT_CLOSE;
        break;
	case V_KEY_YELLOW:
		act = VACT_OK;
		break;
	case V_KEY_BLUE:
		act = VACT_CANCEL;
		break;	        
    default:    
        act = VACT_PASS;
        break;
    }
    
    return act;
}

HILINK_PROFILE_INFO_STRU hilink_profile_info = {0,{0}};

void win_hilink_profile_init(void)
{
    int result = 0;

    MEMSET(&hilink_profile_info, 0 ,sizeof(HILINK_PROFILE_INFO_STRU));
    
    result = hilink_getprofileinfo_fromserver(&hilink_profile_info);

    if(HILINK_OK == result)
    {
        OSD_SetEditFieldContent(&edit_hilink_apn, STRING_ANSI, (UINT32)hilink_profile_info.acapn);
        OSD_SetEditFieldContent(&edit_hilink_user, STRING_ANSI, (UINT32)hilink_profile_info.acuser);
        OSD_SetEditFieldContent(&edit_hilink_password, STRING_ANSI, (UINT32)hilink_profile_info.acpasswd);
    }
}

static PRESULT win_hilink_profile_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
    PRESULT ret = PROC_PASS;
    VACTION unact = VACT_PASS;
    int result = 0;

    switch(event)
    {
    case EVN_PRE_OPEN:
        win_hilink_profile_init();
        wincom_open_title((POBJECT_HEAD)&g_win_hilink_profile,RS_HILINK_PROFILE, 0);
        break;
	case EVN_POST_OPEN:
     	draw_caps_flag(CAPSFLG_L,CAPSFLG_T, 1);
		break;		
    case EVN_PRE_CLOSE:
        /* Make OSD not flickering */
        *((UINT32*)param2) &= ~C_CLOSE_CLRBACK_FLG; 
        break;
	case EVN_POST_CLOSE:
        break;
    case EVN_MSG_GOT:
        if ((CTRL_MSG_SUBTYPE_CMD_EXIT == param1) || (CTRL_MSG_SUBTYPE_CMD_EXIT_ALL == param1))
        {
            ret = PROC_LEAVE;
        }    
        if ((CTRL_MSG_SUBTYPE_CMD_HILINK == param1)&&(HILINK_STATUS_PLUGOUT == param2))
        {
            ret = PROC_LEAVE;
            ap_send_msg(CTRL_MSG_SUBTYPE_CMD_HILINK, HILINK_STATUS_PLUGOUT, FALSE);            
        }
        break;
    case EVN_UNKNOWN_ACTION:
		unact = (VACTION)(param1>>16);
		if(VACT_OK == unact)
		{
            //save profile information            
            ComUniStrToAsc((UINT8 *)OSD_GetEditFieldContent(&edit_hilink_apn),hilink_profile_info.acapn);
            ComUniStrToAsc((UINT8 *)OSD_GetEditFieldContent(&edit_hilink_user),hilink_profile_info.acuser);
            ComUniStrToAsc((UINT8 *)OSD_GetEditFieldContent(&edit_hilink_password),hilink_profile_info.acpasswd);

            result = hilink_setprofileinfo_toserver(hilink_profile_info);
		}
		else if(VACT_CANCEL == unact)
	    {
    		ret = PROC_LEAVE;    
	    }
        break;
    default:
        break;
    }

    return ret; 
}

static VACTION win_hilink_profile_item_con_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act = VACT_PASS;
	switch(key)
	{
	case V_KEY_ENTER:     
		act = VACT_ENTER;
		break; 
	default:
		act = VACT_PASS;
	}

	return act;
}

static PRESULT win_hilink_profile_item_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
    PRESULT ret = PROC_PASS;
    VACTION unact = VACT_PASS;

	switch(event)
	{
    	case EVN_UNKNOWN_ACTION:
    		unact = (VACTION)(param1 >> 16);
    		break;
    	default:
    		break;
	}
    return ret;
}



static VACTION win_hilink_profile_edf_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act = VACT_PASS;
	
	switch(key)
    {
	case V_KEY_0:	case V_KEY_1:	case V_KEY_2:	case V_KEY_3:
	case V_KEY_4:	case V_KEY_5:	case V_KEY_6:	case V_KEY_7:
	case V_KEY_8:	case V_KEY_9:
		act = key - V_KEY_0 + VACT_NUM_0;
		break;
	case V_KEY_LEFT:
		act = VACT_EDIT_LEFT;
		break;
	case V_KEY_RIGHT:
		act = VACT_EDIT_RIGHT;
		break;		
	case V_KEY_RED:
		act = VACT_CAPS;
		break;
	case V_KEY_GREEN:
		act = VACT_DEL;
		break;        
	default:					
		act = VACT_PASS;
	}

	return act;	 
}

enum
{
    IDC_HILINK_APN = 1,
	IDC_HILINK_USER,
    IDC_HILINK_PASSWORD,
};

static PRESULT win_hilink_profile_edf_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT8 bID = 0;
	UINT8 status = 0;
	EDIT_FIELD* edf = NULL;
	UINT8 back_save = 0;
	UINT32 value = 0;
    UINT8 caps = 0;

	mobile_input_type_t mobile_input_type = {0};

	caps = mobile_input_get_caps();

	mobile_input_type.type 		= MOBILE_INPUT_NORMAL;
	mobile_input_type.caps_flag = caps ? MOBILE_CAPS_INIT_UP : MOBILE_CAPS_INIT_LOW;
	mobile_input_type.maxlen    = 17;
	mobile_input_type.fixlen_flag = 0;
	mobile_input_type.callback	= NULL;

	bID = OSD_GetObjID(pObj);

	edf = (EDIT_FIELD*)pObj;

	switch(event)
	{
	case EVN_KEY_GOT:
		if((IDC_HILINK_APN == bID) || 
		   (IDC_HILINK_USER == bID) ||
		   (IDC_HILINK_PASSWORD == bID)) 
	    {
    		ret = mobile_input_proc(edf,(VACTION)(param1>>16), param1 & 0xFFFF, param2);
            if(PROC_LOOP == ret)
            {
    			draw_caps_flag(CAPSFLG_L,CAPSFLG_T, 1);
            }
	    }
		break;
		
	case EVN_PRE_CHANGE:
		break;
	case EVN_POST_CHANGE:
		//libc_printf("POST: ip %xh, get value = %xh\n",param1,OSD_GetEditFieldContent((PEDIT_FIELD)pObj));
		break;

	case EVN_FOCUS_PRE_GET:
	case EVN_PARENT_FOCUS_PRE_GET:
		if((IDC_HILINK_APN == bID) || 
		   (IDC_HILINK_USER == bID) ||
		   (IDC_HILINK_PASSWORD == bID)) 
		{
			mobile_input_init((EDIT_FIELD*)pObj,&mobile_input_type);
			draw_caps_flag(CAPSFLG_L,CAPSFLG_T, 1);
		//	draw_caps_del_colbtn(COLBTN_L, COLBTN_T,1);
		}	
        //mobile_input_init(&edit_hilink_password, NULL);
		//netupg_mobile_input_init(bID);
		break;

	case EVN_FOCUS_PRE_LOSE:
	case EVN_PARENT_FOCUS_PRE_LOSE:	
		if((IDC_HILINK_APN == bID) || 
		   (IDC_HILINK_USER == bID) ||
		   (IDC_HILINK_PASSWORD == bID)) 
		{
			mobile_input_init((EDIT_FIELD*)pObj,&mobile_input_type);
			draw_caps_flag(CAPSFLG_L,CAPSFLG_T, 0);
		//	draw_caps_del_colbtn(COLBTN_L, COLBTN_T,0);
		}
		//netupg_mobile_input_init(bID);
		break;		

	case EVN_DATA_INVALID:		
		win_compopup_init(WIN_POPUP_TYPE_OK);
        win_compopup_set_msg("Invalid address number!", NULL, 0);
		win_compopup_open_ext(&back_save);
		ret = PROC_LOOP;
		break;
	}
	return ret;
}

#endif
